package com.handinfo.android.ui.window;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWInputBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIBlackList implements IUIWindows {
	private DWFrame m_bl_frame = null;
	private DWTitle m_bl_title = null;
	private DWImageBox m_bl_close = null;
	private Bitmap m_bm_close = null;
	private DWBackground m_bl_background = null;
	private DWTextbox m_bl_name = null;
	private DWInputBox m_bl_namein = null;
	private DWButton m_bl_button = null;
	private Bitmap m_bm_button = null;
	private Bitmap m_bm_buttonDown = null;
	private boolean flag = false;

	private void addBlackList() {
		if(DWGameManager.AdpaterType == 2){
			m_bl_frame = new DWFrame(DWGameManager.Screen_Width*3/8, DWGameManager.Screen_Height/4);
		}else{
			m_bl_frame = new DWFrame(300, 120);
		}
		m_bl_frame.setClickClose(false);
		m_bl_frame.setNearAnchor(UISocial.m_si_fram, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_bl_title = new DWTitle("添加黑名单", m_bl_frame);
		// 关闭窗口
		m_bl_close = new DWImageBox(m_bm_close);
		m_bl_close.setTouchZoomIn(20, 20);
		m_bl_close.setNearAnchor(m_bl_title, Tools.RIGHT_TOP,
				Tools.RIGHT_TOP, 0, 0);
		// 背景
		m_bl_background = new DWBackground(m_bl_frame.getShowWidth(), m_bl_frame.getShowHeight());
		m_bl_background.setNearAnchor(m_bl_frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 0, 0);
		// 玩家姓名显示
		m_bl_name = new DWTextbox("玩家姓名");
		if(DWGameManager.AdpaterType == 2){
			m_bl_name.setNearAnchor(m_bl_title, Tools.LEFT_TOP, Tools.LEFT_TOP, DWGameManager.Screen_Width*1/80, DWGameManager.Screen_Height/12);
		}else{
			m_bl_name.setNearAnchor(m_bl_title, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 40);
		}
		// 玩家姓名输入
		if(DWGameManager.AdpaterType == 2){
			m_bl_namein = new DWInputBox(DWGameManager.Screen_Width*15/80, m_bl_name.getShowHeight(), m_bl_frame);
			m_bl_namein.setNearAnchor(m_bl_name, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);
		}else{
			m_bl_namein = new DWInputBox(150, m_bl_name.getShowHeight(), m_bl_frame);
			m_bl_namein.setNearAnchor(m_bl_name, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 120, 0);
		}
		// 确认按钮
		m_bl_button = new DWButton("确定", m_bm_button);
		m_bl_button.setDownImage(m_bm_buttonDown);
		if(DWGameManager.AdpaterType == 2){
			m_bl_button.setNearAnchor(m_bl_frame, Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 0, 0);
		}else{
			m_bl_button.setNearAnchor(m_bl_title, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 100, 80);
		}

		m_bl_frame.addControl(m_bl_background);
		m_bl_frame.addControl(m_bl_title);
		m_bl_frame.addControl(m_bl_close);
		m_bl_frame.addControl(m_bl_name);
		m_bl_frame.addControl(m_bl_namein);
		m_bl_frame.addControl(m_bl_button);
		DWControlsManager.getInstance().addControl(m_bl_frame);

		// 关闭窗口监听
		m_bl_close.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				 UIWindows.getInstance().m_blackList.close((byte)0);
//				DWControlsManager.getInstance().removeControl(m_bl_frame);
			}
		});
		
		m_bl_button.addListener(new DWListener() {
			
			public void OnDoubleClick() {
			}
			
			public void OnClick() {
				UIWindows.getInstance().m_blackList.close((byte)0);
				DWGameManager.getInstance().getSendMessage().sendSocialAddForName(UISocial.SOCIAL_TYPE_BLACKLIST, m_bl_namein.getText().toString());
			}
		});

	}

	public void init() {
		m_bm_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_bm_button = UIWindows.createImage("/img/newui/anniu_2.gnp");
		m_bm_buttonDown = UIWindows.createImage("/img/newui/anniu_2ax.gnp");
	}

	public void open(byte index) {
		if(flag == false){
			addBlackList();
			flag = true;
		}else {
			if(m_bl_frame != null){
				DWControlsManager.getInstance().addControl(m_bl_frame);
			}else{
				return;
			}
			
		}
		
	}

	public void close(byte index) {
		flag = false;
		DWControlsManager.getInstance().removeControl(m_bl_frame);
	}

	public void dispose() {

	}

	public void logic()
	{
		// TODO Auto-generated method stub
		
	}

}
